package com.yuncheng.oaApi.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.oaApi.busService.ReturnZdyService;
import com.yuncheng.oaApi.constant.OaFlowConstant;
import com.yuncheng.oaApi.mapper.OaSpcySqsxJobMapper;
import com.yuncheng.oaApi.vo.OaProcessBusinessVo;
import com.yuncheng.oaApi.vo.OaReturnVo;
import com.yuncheng.oaApi.vo.Result;
import com.yuncheng.utils.ThreadContextHelper;
import com.yuncheng.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "OA我的待办已办接口")
@RestController
@RequestMapping("/api/spzx-oa/mydbyb")
public class AllFlowDbYbServiceController {

    @Resource
    @Lazy
    private OaSpcySqsxJobMapper oaSpcySqsxJobMapper;

    @Resource
    @Lazy
    private ReturnZdyService returnZdyService;



    @AutoLog(value = "当前所有已办")
    @ApiOperation(value = "当前所有已办")
    @GetMapping("YbAllList")
    public HttpResult<?> YbAllList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.OA);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.UserYb(page,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }

    @AutoLog(value = "当前登陆人所有待办")
    @ApiOperation(value = "当前登陆人所有待办")
    @GetMapping("DbList")
    public HttpResult<?> DbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.OA);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllDb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "当前登陆人所有已办")
    @ApiOperation(value = "当前登陆人所有已办")
    @GetMapping("YbList")
    public HttpResult<?> YbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.OA);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }
    //
    @AutoLog(value = "NK_当前登陆人所有待办")
    @ApiOperation(value = "NK_当前登陆人所有待办")
    @GetMapping("NkDbList")
    public HttpResult<?> NkDbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.NK);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllDb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "NK_当前登陆人所有已办")
    @ApiOperation(value = "NK_当前登陆人所有已办")
    @GetMapping("NkYbList")
    public HttpResult<?> NkYbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.NK);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }



    @AutoLog(value = "NK_检查员-当前登陆人所有已办")
    @ApiOperation(value = "NK_检查员当前登陆人所有已办")
    @GetMapping("NkJcyYbList")
    public HttpResult<?> NkJcyYbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){

        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.NK);
        oaProcessBusinessVo.setFlcmb(OaFlowConstant.NK_BXSQLC);
        oaProcessBusinessVo.setFbxlx("检查员报销");
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getJcyAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }





    //
    @AutoLog(value = "DF_当前登陆人所有待办")
    @ApiOperation(value = "DF_当前登陆人所有待办")
    @GetMapping("DFDbList")
    public HttpResult<?> DFDbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.DF);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllDb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "DF_当前登陆人所有已办")
    @ApiOperation(value = "DF_当前登陆人所有已办")
    @GetMapping("DFYbList")
    public HttpResult<?> DFYbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.DF);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "YY_当前登陆人所有待办")
    @ApiOperation(value = "YY_当前登陆人所有待办")
    @GetMapping("YyDbList")
    public HttpResult<?> YyDbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.YWYY);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllDb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "YY_当前登陆人所有已办")
    @ApiOperation(value = "YY_当前登陆人所有已办")
    @GetMapping("YyYbList")
    public HttpResult<?> YyYbList(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "true") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        if (user == null){
            return HttpResult.error("请重新登录，Token已失效！");
        }
        oaProcessBusinessVo.setFywlx(OaFlowConstant.YWYY);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }




    @AutoLog(value = "撤回查询")
    @ApiOperation(value = "撤回查询")
    @GetMapping("queryAllYbJob")
    public HttpResult<?> queryAllYbJob(String lcmbbm,String jobid){
        Result result = returnZdyService.getCurrentJobPrevious(lcmbbm, jobid);
        return HttpResult.ok(result);

    }

    @AutoLog(value = "撤回")
    @ApiOperation(value = "撤回")
    @PostMapping("returnUpperzdyFlowJob")
    public HttpResult<?> returnUpperzdyFlowJob(@RequestBody OaReturnVo oaReturnVo){
        Result result = returnZdyService.returnZdJob(oaReturnVo);
        return HttpResult.ok(result);

    }

    @AutoLog(value = "获取当前登录人")
    @ApiOperation(value = "获取当前登录人")
    @GetMapping(value = "getNowUser")
    public HttpResult getNowUser(){
        CurrentUserVo currentUser = ThreadContextHelper.getCurrentUser();
        Map result = new HashMap();
        if (currentUser != null) {
            result.put("id", currentUser.getId());
            result.put("name", currentUser.getName());
            result.put("deptName", currentUser.getDeptName());
        }
        return HttpResult.ok(result);
    }


    @AutoLog(value = "OA_数据修订列表")
    @ApiOperation(value = "OA_数据修订列表")
    @GetMapping(value = "oasjxd")
    public HttpResult<?> oaSjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        oaProcessBusinessVo.setFywlx(OaFlowConstant.OA);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);
        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }


    @AutoLog(value = "NK_数据修订列表")
    @ApiOperation(value = "NK_数据修订列表")
    @GetMapping(value = "nksjxd")
    public HttpResult<?> nkSjxd(
            @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "onlyCurrentUser", defaultValue = "false") boolean onlyCurrentUser,
            OaProcessBusinessVo oaProcessBusinessVo){
        CurrentUserVo user = ThreadContextHelper.getCurrentUser();
        oaProcessBusinessVo.setFywlx(OaFlowConstant.NK);
        Page<OaProcessBusinessVo> page = new Page<>(pageNo, pageSize);
        IPage<OaProcessBusinessVo> list = oaSpcySqsxJobMapper.getAllYb(page,onlyCurrentUser,user,oaProcessBusinessVo);
        return HttpResult.ok(list);
    }



}
